{include file="include/top"}
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">商品管理</a>
            <a>
              <cite>分类列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-radius layui-btn-normal" onclick="edit()"><i class="layui-icon">&#xe654;</i>添加分类</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>栏目名</th>
                            <th>排序</th>
                            <th>状态</th>
                            <th>操作</th>
                        </thead>
                        <tbody class="x-cate">
                        {volist name="list" id="data"}
                            <input type="hidden" id="parent" value="{$data.ca_id}">
                            <td>{$data.ca_id}</td>
                            <td>{$data.ca_name}-{if $data.ca_parent == 1}特价超市{else}抢先兑{/if}</td>
                            <td>{$data.ca_sort}</td>
                            {if $data.ca_show == 1}
                            <td onclick="member_stop(this,'category','ca_id','{$data.ca_id}','ca_show',2,'禁用')">
                                <input type="checkbox" name="switch"  lay-text="开启|停用" checked="" lay-skin="switch">
                            </td>
                            {elseif $data.ca_show == 2}
                            <td onclick="member_stop(this,'category','ca_id','{$data.ca_id}','ca_show',1,'开启')">
                                <input type="checkbox" name="switch"  lay-text="开启|停用" lay-skin="switch">
                            </td>
                            {/if}
                            <td class="td-manage">
                                <button class="layui-btn layui-btn layui-btn-xs"  onclick="cha('{$data.ca_id}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });
    /*状态*/
    function member_stop(obj,table,id,where,field,state,title){
        $.ajax({
            type: 'POST',
            url: '{:url("index/updateStatus")}',
            dataType: 'json',
            data : {table:table,id:id,where:where,field:field,state:state},
            success: function(data){
                if(data.code>0){
                    layer.msg('已'+title,{icon:1,time:1000});
                    setTimeout(function () {
                        location.reload();
                    }, 1000);
                }else{
                    layer.msg(title+'失败',{icon:5,time:1000});
                }
            },
            error:function(data) {
                console.log(data.msg);
            },
        });
    }
    //添加
    function edit(id = '')
    {
        var url = '{:url("Goods/cate_add")}';
        var desc = '添加';
        var arr = ['80%','80%'];
        var loading =  layer.load(0, {shade: false});
        layer.open({
            type: 2,
            title:desc,
            area: arr,
            content: url
        });
        layer.close(loading);
    }

    //编辑
    function cha(id = '')
    {
        var url = '{:url("Goods/cate_edit",["id"=>"getId"])}';
        url = url.replace('getId',id);
        var loading =  layer.load(0, {shade: false});
        layer.open({
            type: 2,
            title:'编辑',
            area: ['80%','80%'],
            content: url
        });
        layer.close(loading);
    }
</script>
</html>